package com.test.es;

import java.net.InetSocketAddress;

import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.Before;
import org.junit.Test;

public class ESTest2 {

	private TransportClient client;

	@Before
	public void testBefore() {
		Settings settings = Settings.builder().put("cluster.name", "my-5i5j").build();
		client = new PreBuiltTransportClient(settings)
				.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("10.1.66.76", 9300)));
	}

	@Test
	public void testSearch() {
		/*SearchRequestBuilder searchRequestBuilder = client.prepareSearch("cc_index", "cc_type", "1");
		SearchResponse response = searchRequestBuilder.setTypes("user").setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
				.setQuery(QueryBuilders.termQuery("user", "jinmao"))
				.setPostFilter(QueryBuilders.rangeQuery("age").from(0).to(1)).setFrom(0).setSize(2).setExplain(true)
				.execute().actionGet();
		SearchHits hits = response.getHits();
		for (SearchHit searchHit : hits) {
			for (Iterator<SearchHitField> iterator = searchHit.iterator(); iterator.hasNext();) {
				SearchHitField next = iterator.next();
				System.out.println(next.getValues());
			}
		}*/
		
		
				
		/*
		 * SearchResponse response = client.prepareSearch().execute().actionGet();
		 * System.out.println(response);
		 */
	}
}
